home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16454 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  57 lines

  1. Newsgroups: comp.lang.c++
  2. Path: twisto.eng.hou.compaq.com!news
  3. From: Saurabh Dixit <saurabhd@bangate.compaq.com>
  4. Subject: Re: Mutually referring header files
  5. Message-ID: <316C36F8.4545@bangate.compaq.com>
  6. Sender: news@twisto.eng.hou.compaq.com (System Administrator)
  7. Mime-Version: 1.0
  8. X-Mailer: Mozilla 2.0 (WinNT; I)
  9. Content-Type: text/plain; charset=us-ascii
  10. Organization: Compaq Computer Corporation
  11. Date: Wed, 10 Apr 1996 22:32:24 GMT
  12. References: <4ked7q$8g3@dub-news-svc-1.compuserve.com> <lt91g4ouif.fsf@kitz.inferenzsysteme.informatik.th-darmstadt.de>
  13. X-Nntp-Posting-Host: 172.18.176.8
  14. Content-Transfer-Encoding: 7bit
  15.  
  16. I think the following should work
  17.  
  18. File A.h
  19. class B; // forward declaration
  20. class A {
  21.     B* b;
  22. };
  23.  
  24. File B.h
  25. class A; // forward declaration
  26. class B {
  27.     A* a;
  28. };
  29.  
  30. File A.cpp
  31. #include "A.h"
  32. #include "B.h"
  33. ....
  34.  
  35. File B.cpp
  36. #include "B.h"
  37. #include "A.h"
  38. ....
  39.  
  40. Note that if you are referring to either class through pointers,
  41. then you don't have to include the header for one in the other.
  42. You can include the header for one in the other's implementation
  43. file instead where you will actually access the object.
  44.  
  45. Please also refer to Enno Sandner's response of using
  46. #ifndefs and #defines for class headers ala A_H and B_H in
  47. case you plan to include either of the class headers in
  48. multiple source files.
  49.  
  50. Hope this helps
  51. -- 
  52. Saurabh Dixit                     ,,,
  53. Compaq Computer Corporation      (o o)    
  54. _____________________________oOOo-(_)-oOOo__________
  55. I believe the egg came before the chicken...
  56. xxxx
  57.